<template>
  <view>
    <view class="container">
      <!-- 表单内容 -->
      <u-form class="form-content">
        <u-form-item label="所属机构" class="form-item" label-width="120">
          <view class="arrow-icon-groud">
            <u-input
              class="custom-input"
              v-model="formData.plateColor"
              placeholder="请选择所属机构"
              @click="changeOpenCarColor"
            />
            <!-- 向下/向上箭头图标 -->
            <u-icon
              :name="plateColorPickerVisible ? 'arrow-up' : 'arrow-down'"
              size="20"
              class="arrow-icon"
            />
          </view>

          <area-picker
            ref="carPicker"
            :title="title"
            titleColor="#808080"
            titleFontSize="14px"
            cancelType="icon"
            cancelColor="#999999"
            cancleFontSize="28rpx"
            confirmColor="#2877FF"
            confirmFontSize="14px"
            confirmFontWeight="500"
            itemFontSize="14px"
            @onClose="closeCarPicker"
            @onConfirm="confirmCarPicker"
            :pickerList="list"
          />
        </u-form-item>
        <!-- 监测站名称输入 -->
        <u-form-item label="监测站名称" class="form-item" label-width="120">
          <u-input
            v-model="formData.plateNumber"
            placeholder="请输入监测站名称"
            class="custom-input"
          />
        </u-form-item>

        <!-- 所属机构选择 -->
        <u-form-item label="企业性质" class="form-item" label-width="120">
          <view class="arrow-icon-groud">
            <u-input
              class="custom-input"
              v-model="formData.changeDsType"
              placeholder="请选择企业性质"
              @click="changeDsType"
            />
            <!-- 向下/向上箭头图标 -->
            <u-icon
              :name="plateColorPickerVisible ? 'arrow-up' : 'arrow-down'"
              size="20"
              class="arrow-icon"
            />
          </view>

          <area-picker
            ref="dsTypePicker"
            :title="dsTypeTitle"
            titleColor="#808080"
            titleFontSize="14px"
            cancelType="icon"
            cancelColor="#999999"
            cancleFontSize="28rpx"
            confirmColor="#2877FF"
            confirmFontSize="14px"
            confirmFontWeight="500"
            itemFontSize="14px"
            @onClose="closeDsTypePicker"
            @onConfirm="confirmDsTypePicker"
            :pickerList="changeDsTypeList"
          />
        </u-form-item>
      </u-form>

      <!-- 查询按钮 -->
      <view class="btn-container">
        <u-button @click="goToquerycert()">立即查询</u-button>
      </view>

      <view
        class="card"
        v-for="(item, index) in carList"
        :key="index"
        @click="goTocertDetails"
      >
        <view class="car-info">
          <view class="car-top">
            <view class="car-top-left">
              <text class="car-number">{{ item.carNumber }}</text>
            </view>
          </view>

          <view class="car-bottom">
            <up-icon name="photo"></up-icon>
            <view class="car-bottom-right">
              <up-icon name="phone"></up-icon>
              <text class="transport-code">{{ item.transportCode }}</text>
            </view>
          </view>
          <view class="car-bottom-btn">
            <view class="car-bottom-btn-item">
              <text>位置信息</text>
            </view>
            <view class="car-bottom-btn-item" @click="goTocertDetails">
              <text>查看详情</text>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>
<script>
import { changePlatecolor, changeDsType } from "@/common/util_complete.js";
export default {
  data() {
    return {
      formData: {
        region: "",
        plateNumber: "",
        plateColor: "",
        transportNumber: "",
        changeDsType: "",
      },
      title: "所属机构选择",
      dsTypeTitle: "企业性质选择",
      plateColorPickerVisible: false,

      list: [], // 所属机构选择

      changeDsTypeList: [], // 企业性质选择
      carList: [
        {
          carNumber: "xxxxxxx有限公司",
          transportCode: "20881206832",
        },
        {
          carNumber: "xxxxxxx有限公司",
          transportCode: "20881206832",
        },
        {
          carNumber: "xxxxxxx有限公司",
          transportCode: "20881206832",
        },
      ],
    };
  },
  onLoad(options) {
    // this.populateList(); // 在加载时填充数据
    this.list = changePlatecolor(this.list);
    this.changeDsTypeList = changeDsType(this.changeDsTypeList);
  },
  methods: {
    changeDsType() {
      this.$refs.dsTypePicker._open();
    },
    closeDsTypePicker() {
      this.$refs.dsTypePicker._close();
    },
    confirmDsTypePicker(checkedValue) {
      this.formData.changeDsType = checkedValue;
    },
    changeOpenCarColor() {
      this.$refs.dsTypePicker._open();
    },
    //关闭选择器
    closeCarPicker() {
      this.$refs.carPicker._close();
    },
    confirmCarPicker(checkedValue) {
      this.formData.plateColor = checkedValue;
    },

    goToquerycert() {
      this.show = true;
    },
    // 查看详情
    goTocertDetails() {
      uni.navigateTo({
        url: "/pages/hub_zsyg/prac/detection/detectdetails/detectdetails",
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.container {
  width: 100%;
  padding: 10px;
  background-color: #f3f6fa;
  height: 100vh;
  box-sizing: border-box;
}

.form-content {
  background-color: #ffffff;
  padding: 0;
  /* 去掉 padding */
  border-radius: 5px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.form-item {
  padding: 0 10px;
  border-bottom: 1px solid #f1f1f1;
  /* 设置下边框 */
}
.custom-input {
  border: none;
  /* 去掉输入框的边框 */
  background-color: transparent;
  /* 使背景透明 */
}

.arrow-icon-groud {
  position: relative;
  flex: 1;

  .arrow-icon {
    position: absolute !important;
    right: 20px;
    top: 10px;
  }
}

.btn-container {
  margin-top: 30px;
  text-align: center;

  width: 100%;
  box-sizing: border-box;
  ::v-deep .u-button--info[data-v-461e713c] {
    width: 100%;
    background-color: #2877ff;
    color: #ffffff;
  }
}

/* 定义卡片的背景、圆角和阴影 */
.card {
  background-color: #fff;
  border-radius: 10px;
  padding: 15px;
  margin: 10px 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* 图标与车辆信息的布局 */
.car-info {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;

  .car-top {
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 10px 0;
    border-bottom: 1px solid #f1f1f1;

    margin-bottom: 10px;

    .car-top-left {
      display: flex;
      align-items: center;
      flex: 1;
      .car-number {
        margin-left: 10px;
        font-size: 18px;
        color: #333333;
      }
    }
  }
  .car-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;

    .car-bottom-right {
      display: flex;
      align-items: center;
    }
  }
  .car-bottom-btn {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    .car-bottom-btn-item {
      margin-left: 10px;
      color: #2877ff;
      font-size: 12px;
    }
  }
  .transport-code {
    font-size: 12px;
    color: #79829c;
  }
  .icon {
    width: 40px;
    height: 40px;
  }
}
</style>
